package com.lswms.modules.lswms.dao.check;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lswms.common.dao.BaseDao;
import com.lswms.modules.lswms.entity.check.CheckdetailEntity;

/**
 * 盘点明细
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-07-08
 */
@Mapper
public interface CheckdetailDao extends BaseDao<CheckdetailEntity> {

	@Select("select lswms_checkdetail.* ,lswms_sku.descr descr , lswms_sku.factorycdoe factorycdoe,  lswms_codelist.listname statusstr , lswms_sku.isuniquecode isuniquecode "
			+ "from lswms_checkdetail left join lswms_sku on lswms_checkdetail.sku = lswms_sku.sku  "
			+ "		left join lswms_codelist on lswms_checkdetail.status = lswms_codelist.list and code='CheckStatus'   ${ew.customSqlSegment}")
	List<CheckdetailEntity> selectListBySql(@Param(Constants.WRAPPER)QueryWrapper<CheckdetailEntity> queryWrapper);

	@Select(value ="select isnull( max(line),0)+1 from lswms_checkdetail where checkkey=#{checkkey} ")
	int getNextCheckdetailLine(@Param("checkkey")String checkkey);

	@Select("select lswms_checkdetail.* ,lswms_sku.descr descr, lswms_sku.factorycdoe factorycdoe,  lswms_codelist.listname statusstr, lswms_sku.isuniquecode isuniquecode  "
			+ "from lswms_checkdetail left join lswms_sku on lswms_checkdetail.sku = lswms_sku.sku  "
			+ "		left join lswms_codelist on lswms_checkdetail.status = lswms_codelist.list and code='CheckStatus'   ${ew.customSqlSegment}")
	IPage<CheckdetailEntity> selectPageBySql(IPage<CheckdetailEntity> page, @Param(Constants.WRAPPER)QueryWrapper<CheckdetailEntity> wrapper);

	@Select("select lswms_checkdetail.* ,lswms_sku.descr descr, lswms_sku.factorycdoe factorycdoe,  lswms_codelist.listname statusstr, lswms_sku.isuniquecode isuniquecode  "
			+ "from lswms_checkdetail left join lswms_sku on lswms_checkdetail.sku = lswms_sku.sku  "
			+ "		left join lswms_codelist on lswms_checkdetail.status = lswms_codelist.list and code='CheckStatus'   ${ew.customSqlSegment}")
	List<CheckdetailEntity> listBySql(@Param(Constants.WRAPPER)QueryWrapper<CheckdetailEntity> wrapper);
	
}